﻿Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class frmQuan
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnNew As System.Windows.Forms.Button
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnDelete1 As System.Windows.Forms.Button
    Friend WithEvents txtTen_QUAN As System.Windows.Forms.TextBox
    Friend WithEvents txtMa_QUAN As System.Windows.Forms.TextBox
    Friend WithEvents txtGchu As System.Windows.Forms.TextBox
    Friend WithEvents BtnClose As System.Windows.Forms.Button
    Friend WithEvents BtnIn As System.Windows.Forms.Button
    Friend WithEvents Label5 As System.Windows.Forms.Label
    ' Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    Friend WithEvents DataGridView1 As MyDataGridView
    Friend WithEvents TblquanBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents DataSetForm_Don As MEKONG.DataSetForm_Don
    Friend WithEvents CboTinh As MTGCComboBox
    Friend WithEvents GhichuDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MatinhDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MaquanDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TenquanDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ghichu As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ma_tinh As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TxtTen_Tinh As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmQuan))
        Me.btnSave = New System.Windows.Forms.Button
        Me.txtGchu = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.txtTen_QUAN = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.txtMa_QUAN = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnNew = New System.Windows.Forms.Button
        Me.btnDelete1 = New System.Windows.Forms.Button
        Me.BtnClose = New System.Windows.Forms.Button
        Me.BtnIn = New System.Windows.Forms.Button
        Me.Label5 = New System.Windows.Forms.Label
        Me.TxtTen_Tinh = New System.Windows.Forms.TextBox
        ' Me.DataGridView1 = New System.Windows.Forms.DataGridView
        Me.DataGridView1 = New MyDataGridView
        Me.TblquanBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.DataSetForm_Don = New MEKONG.DataSetForm_Don
        Me.CboTinh = New MTGCComboBox
        Me.MaquanDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TenquanDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ghichu = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ma_tinh = New System.Windows.Forms.DataGridViewTextBoxColumn
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TblquanBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetForm_Don, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnSave
        '
        Me.btnSave.BackColor = System.Drawing.Color.Transparent
        Me.btnSave.Image = CType(resources.GetObject("btnSave.Image"), System.Drawing.Image)
        Me.btnSave.Location = New System.Drawing.Point(240, 527)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(96, 24)
        Me.btnSave.TabIndex = 5
        Me.btnSave.UseVisualStyleBackColor = False
        '
        'txtGchu
        '
        Me.txtGchu.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtGchu.Location = New System.Drawing.Point(128, 120)
        Me.txtGchu.MaxLength = 100
        Me.txtGchu.Name = "txtGchu"
        Me.txtGchu.Size = New System.Drawing.Size(576, 22)
        Me.txtGchu.TabIndex = 3
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(71, 121)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(54, 16)
        Me.Label4.TabIndex = 16
        Me.Label4.Text = "Ghi Chú"
        '
        'txtTen_QUAN
        '
        Me.txtTen_QUAN.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTen_QUAN.Location = New System.Drawing.Point(328, 84)
        Me.txtTen_QUAN.MaxLength = 50
        Me.txtTen_QUAN.Name = "txtTen_QUAN"
        Me.txtTen_QUAN.Size = New System.Drawing.Size(376, 22)
        Me.txtTen_QUAN.TabIndex = 2
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(269, 90)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(59, 16)
        Me.Label3.TabIndex = 14
        Me.Label3.Text = "Tên Quận"
        '
        'txtMa_QUAN
        '
        Me.txtMa_QUAN.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtMa_QUAN.Location = New System.Drawing.Point(128, 88)
        Me.txtMa_QUAN.MaxLength = 10
        Me.txtMa_QUAN.Name = "txtMa_QUAN"
        Me.txtMa_QUAN.Size = New System.Drawing.Size(138, 22)
        Me.txtMa_QUAN.TabIndex = 1
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(71, 90)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(57, 16)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "Mã Quận"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(256, 13)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(288, 24)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "DANH MỤC QUẬN"
        '
        'btnNew
        '
        Me.btnNew.Image = CType(resources.GetObject("btnNew.Image"), System.Drawing.Image)
        Me.btnNew.Location = New System.Drawing.Point(120, 527)
        Me.btnNew.Name = "btnNew"
        Me.btnNew.Size = New System.Drawing.Size(96, 24)
        Me.btnNew.TabIndex = 6
        '
        'btnDelete1
        '
        Me.btnDelete1.Image = CType(resources.GetObject("btnDelete1.Image"), System.Drawing.Image)
        Me.btnDelete1.Location = New System.Drawing.Point(360, 527)
        Me.btnDelete1.Name = "btnDelete1"
        Me.btnDelete1.Size = New System.Drawing.Size(88, 24)
        Me.btnDelete1.TabIndex = 29
        '
        'BtnClose
        '
        Me.BtnClose.Image = CType(resources.GetObject("BtnClose.Image"), System.Drawing.Image)
        Me.BtnClose.Location = New System.Drawing.Point(592, 527)
        Me.BtnClose.Name = "BtnClose"
        Me.BtnClose.Size = New System.Drawing.Size(88, 24)
        Me.BtnClose.TabIndex = 30
        '
        'BtnIn
        '
        Me.BtnIn.Image = CType(resources.GetObject("BtnIn.Image"), System.Drawing.Image)
        Me.BtnIn.Location = New System.Drawing.Point(480, 527)
        Me.BtnIn.Name = "BtnIn"
        Me.BtnIn.Size = New System.Drawing.Size(88, 24)
        Me.BtnIn.TabIndex = 39
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(71, 56)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(57, 16)
        Me.Label5.TabIndex = 41
        Me.Label5.Text = "Mã Tỉnh"
        '
        'TxtTen_Tinh
        '
        Me.TxtTen_Tinh.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtTen_Tinh.Location = New System.Drawing.Point(273, 53)
        Me.TxtTen_Tinh.MaxLength = 50
        Me.TxtTen_Tinh.Name = "TxtTen_Tinh"
        Me.TxtTen_Tinh.Size = New System.Drawing.Size(431, 22)
        Me.TxtTen_Tinh.TabIndex = 42
        '
        'DataGridView1
        '
        Me.DataGridView1.AllowUserToAddRows = False
        Me.DataGridView1.AllowUserToDeleteRows = False
        Me.DataGridView1.AllowUserToResizeColumns = False
        Me.DataGridView1.AutoGenerateColumns = False
        Me.DataGridView1.BackgroundColor = System.Drawing.Color.LightBlue
        Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.MaquanDataGridViewTextBoxColumn, Me.TenquanDataGridViewTextBoxColumn, Me.ghichu, Me.ma_tinh})
        Me.DataGridView1.DataSource = Me.TblquanBindingSource
        Me.DataGridView1.Location = New System.Drawing.Point(33, 163)
        Me.DataGridView1.Name = "DataGridView1"
        Me.DataGridView1.ReadOnly = True
        Me.DataGridView1.Size = New System.Drawing.Size(727, 345)
        Me.DataGridView1.TabIndex = 48
        '
        'TblquanBindingSource
        '
        Me.TblquanBindingSource.DataMember = "tbl_quan"
        Me.TblquanBindingSource.DataSource = Me.DataSetForm_Don
        '
        'DataSetForm_Don
        '
        Me.DataSetForm_Don.DataSetName = "DataSetForm_Don"
        Me.DataSetForm_Don.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'CboTinh
        '
        Me.CboTinh.ArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CboTinh.ArrowColor = System.Drawing.Color.Black
        Me.CboTinh.BindedControl = Nothing
        Me.CboTinh.BorderStyle = MTGCComboBox.TipiBordi.Fixed3D
        Me.CboTinh.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal
        Me.CboTinh.ColumnNum = 1
        Me.CboTinh.ColumnWidth = "121"
        Me.CboTinh.DisabledArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CboTinh.DisabledArrowColor = System.Drawing.Color.LightGray
        Me.CboTinh.DisabledBackColor = System.Drawing.SystemColors.Control
        Me.CboTinh.DisabledBorderColor = System.Drawing.SystemColors.InactiveBorder
        Me.CboTinh.DisabledForeColor = System.Drawing.SystemColors.GrayText
        Me.CboTinh.DisplayMember = "Text"
        Me.CboTinh.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.CboTinh.DropDownBackColor = System.Drawing.Color.FromArgb(CType(CType(193, Byte), Integer), CType(CType(210, Byte), Integer), CType(CType(238, Byte), Integer))
        Me.CboTinh.DropDownForeColor = System.Drawing.Color.Black
        Me.CboTinh.DropDownStyle = MTGCComboBox.CustomDropDownStyle.DropDown
        Me.CboTinh.DropDownWidth = 141
        Me.CboTinh.GridLineColor = System.Drawing.Color.LightGray
        Me.CboTinh.GridLineHorizontal = False
        Me.CboTinh.GridLineVertical = False
        Me.CboTinh.LoadingType = MTGCComboBox.CaricamentoCombo.ComboBoxItem
        Me.CboTinh.Location = New System.Drawing.Point(129, 54)
        Me.CboTinh.ManagingFastMouseMoving = True
        Me.CboTinh.ManagingFastMouseMovingInterval = 30
        Me.CboTinh.Name = "CboTinh"
        Me.CboTinh.SelectedItem = Nothing
        Me.CboTinh.SelectedValue = Nothing
        Me.CboTinh.Size = New System.Drawing.Size(138, 21)
        Me.CboTinh.TabIndex = 0
        '
        'MaquanDataGridViewTextBoxColumn
        '
        Me.MaquanDataGridViewTextBoxColumn.DataPropertyName = "ma_quan"
        Me.MaquanDataGridViewTextBoxColumn.HeaderText = "Mã quận"
        Me.MaquanDataGridViewTextBoxColumn.Name = "MaquanDataGridViewTextBoxColumn"
        Me.MaquanDataGridViewTextBoxColumn.ReadOnly = True
        '
        'TenquanDataGridViewTextBoxColumn
        '
        Me.TenquanDataGridViewTextBoxColumn.DataPropertyName = "ten_quan"
        Me.TenquanDataGridViewTextBoxColumn.HeaderText = "Tên quận"
        Me.TenquanDataGridViewTextBoxColumn.Name = "TenquanDataGridViewTextBoxColumn"
        Me.TenquanDataGridViewTextBoxColumn.ReadOnly = True
        Me.TenquanDataGridViewTextBoxColumn.Width = 300
        '
        'ghichu
        '
        Me.ghichu.DataPropertyName = "ghichu"
        Me.ghichu.HeaderText = "Ghi chú"
        Me.ghichu.Name = "ghichu"
        Me.ghichu.ReadOnly = True
        Me.ghichu.Width = 150
        '
        'ma_tinh
        '
        Me.ma_tinh.DataPropertyName = "ma_tinh"
        Me.ma_tinh.HeaderText = "Mã tỉnh"
        Me.ma_tinh.Name = "ma_tinh"
        Me.ma_tinh.ReadOnly = True
        '
        'frmQuan
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.LightBlue
        Me.ClientSize = New System.Drawing.Size(792, 573)
        Me.Controls.Add(Me.CboTinh)
        Me.Controls.Add(Me.DataGridView1)
        Me.Controls.Add(Me.TxtTen_Tinh)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.BtnIn)
        Me.Controls.Add(Me.BtnClose)
        Me.Controls.Add(Me.txtGchu)
        Me.Controls.Add(Me.txtTen_QUAN)
        Me.Controls.Add(Me.txtMa_QUAN)
        Me.Controls.Add(Me.btnDelete1)
        Me.Controls.Add(Me.btnNew)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmQuan"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Danh Muc Quan"
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TblquanBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetForm_Don, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Private data1 As DataTable
    Private da As MySqlDataAdapter
    Dim sqlQuery As String = ""
    Dim data As DataTable
    Dim myDT As New DataTable
    Dim strError As String = ""
    Dim myform As Form
    Sub SetclearData()
        txtMa_QUAN.Text = ""
        txtTen_QUAN.Text = ""
        CboTinh.Text = ""
        txtGchu.Text = ""

    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        ' Kiểm tra có nhập liệu chưa ?
        If Me.checkInput(txtMa_QUAN.Text, txtTen_QUAN.Text) Then
            Dim txtMaQuan = Me.txtMa_QUAN.Text.Trim
            sqlQuery = "SELECT ma_quan FROM tbl_quan WHERE ma_quan = '" & txtMaQuan & "'"
            Dim existedMamon As Integer = moduleDatabaseConn.CheckRecordExisted(sqlQuery)
            If existedMamon = 1 Then ' Update record
                sqlQuery = "UPDATE tbl_quan "
                sqlQuery += "SET "
                sqlQuery += "ma_quan = '" & txtMaQuan & "'"
                sqlQuery += ", ten_quan = '" & Me.txtTen_QUAN.Text.Trim & "'"
                sqlQuery += ", ghichu = '" & Me.txtGchu.Text.Trim & "'"
                sqlQuery += ", ma_tinh = '" & Me.CboTinh.Text.Trim & "'"
                sqlQuery += " WHERE ma_quan = '" & txtMaQuan & "'"
                Dim updated As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If updated = 1 Then
                    MessageBox.Show("Cập nhật thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_quan"
                    Me.loadDanhSachQuan(sqlQuery)
                Else
                    MessageBox.Show("Cập nhật thông tin không thành công: " & globalVariale.sqlMsgError)
                End If

            Else
                If existedMamon = 0 Then ' Insert record
                    sqlQuery = "INSERT INTO tbl_quan "
                    sqlQuery += "(ma_quan, ten_quan,ghichu,ma_tinh) "
                    sqlQuery += "VALUES "
                    sqlQuery += "("
                    sqlQuery += "'" & txtMaQuan.ToUpper & "', "
                    sqlQuery += "'" & Me.txtTen_QUAN.Text.Trim & "', "
                    sqlQuery += "'" & Me.txtGchu.Text.Trim & "',"
                    sqlQuery += "'" & Me.CboTinh.Text.Trim & "' "
                    sqlQuery += ")"
                    Dim inserted As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                    If inserted = 1 Then
                        MessageBox.Show("Thêm thông tin thành công !")
                        sqlQuery = "SELECT * FROM tbl_quan"
                        Me.loadDanhSachQuan(sqlQuery)
                    Else
                        MessageBox.Show("Thêm thông tin không thành công: " & globalVariale.sqlMsgError)
                    End If
                Else ' SQLExeption: existedMaQuocGia = -1
                    MessageBox.Show("Lấy dữ liệu bị lỗi: " & globalVariale.sqlMsgError, "Lấy dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
            End If
        End If


    End Sub

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        SetclearData()
        txtMa_QUAN.Focus()
    End Sub


    Private Sub btnDelete1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete1.Click
        Dim txtMaQuan As String = Trim(Me.txtMa_QUAN.Text)
        If txtMaQuan = "" Then
            MessageBox.Show("Bạn chưa chọn Mã để xóa !")
        Else
            Dim txtTenQuan As String = Trim(Me.txtTen_QUAN.Text)
            moduleConstants.MessageWarning = "Bạn có muốn xóa " & txtMaQuan & "(" & txtTenQuan & ") ?"

            If MessageBox.Show(moduleConstants.MessageWarning, globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
                Dim sqlQuery As String = "DELETE FROM tbl_quan WHERE ma_quan = '" & txtMaQuan & "'"
                Dim deleting As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If deleting = 1 Then
                    MessageBox.Show("Xóa thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_quan"
                    Me.loadDanhSachQuan(sqlQuery)
                    SetclearData()
                Else
                    MessageBox.Show("Xóa thông tin không thành công: " & globalVariale.sqlMsgError)
                End If
            End If
        End If
    End Sub

    Private Sub frmquan_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        moduleUtils.setDinhDangVietNam()
        Me.loadDanhSachQuan("SELECT * FROM tbl_quan")
        Me.loadDanhSachTinh()
    End Sub

    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Me.Close()
    End Sub

    Function checkInput(ByVal ma As String, ByVal ten As String) As Boolean
        Dim result As Boolean = True
        If ma = "" Then
            MessageBox.Show("Bạn chưa chọn Mã Quận !")
            result = False
        Else
            If ten = "" Then
                MessageBox.Show("Bạn chưa nhập tên Quận !")
                result = False
            End If
        End If
        Return result
    End Function

    Private Sub loadDanhSachQuan(ByVal sqlQuery As String)
        Me.DataGridView1.DataSource = moduleDatabaseConn.GetDataTable(sqlQuery)
    End Sub
    Private Sub loadDanhSachTinh()
        Dim sqlQuery As String = ""
        sqlQuery = "SELECT ma_tinh, ten_tinh FROM tbl_tinh ORDER BY ma_tinh"
        data1 = moduleDatabaseConn.GetDataTable(sqlQuery)
        CboTinh.Items.Clear()
        CboTinh.LoadingType = MTGCComboBox.CaricamentoCombo.DataTable
        CboTinh.ColumnNum = 2
        CboTinh.ColumnWidth = "100;250"
        CboTinh.HighlightBorderColor = Color.Black
        CboTinh.GridLineHorizontal = True
        CboTinh.GridLineVertical = True
        CboTinh.ItemHeight = 17
        CboTinh.DropDownHeight = 300
        CboTinh.SourceDataTable = data1
        CboTinh.SelectedIndex = 0


    End Sub


    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
        Me.txtMa_QUAN.Text = Me.DataGridView1.Item(0, iRow).Value
        Me.txtTen_QUAN.Text = Me.DataGridView1.Item(1, iRow).Value
        Me.txtGchu.Text = Me.DataGridView1.Item(2, iRow).Value
        Me.CboTinh.Text = Me.DataGridView1.Item(3, iRow).Value
    End Sub

    Private Sub BtnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnIn.Click
        FrmCrQuan.Show()
    End Sub

    Private Sub CboTinh_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboTinh.SelectedIndexChanged
        Me.TxtTen_Tinh.Text = Me.CboTinh.SelectedItem.Col2
    End Sub
End Class


